#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import pathlib
import subprocess

FOLDER = pathlib.Path('~/Folders/wifiCrack/').expanduser()

p = subprocess.Popen(['aircrack-ng', '-w', FOLDER / '字典2.txt', FOLDER / 'airportSniffpstSnL.cap'],
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

stdout, stderr = p.communicate()
import chardet
d = chardet.detect(stdout)

with open('f', 'wb') as fo:
    fo.write(stdout)

with open('f', 'rb') as fo:
    s = fo.read()

# stdout = stdout[:].decode(d['encoding'])
for a in stdout.split('\n'):
    try:
        a = a.decode(d['encoding'])
        if '1 handshake' in a:
            print(a)
    except:
        pass

# print(stdout)
# import os
# os.system('aircrack-ng -w %s %s' % (FOLDER / '字典.txt', FOLDER / 'airportSniffvYPEvI.cap'))